Manage promo codes

PromocodeManager

Manage promo codes.

class yandex_b2b_go.promocode.PromocodeManager

Attribute

PromocodeOrderManager

Manage promo code orders.

class yandex_b2b_go.promocode.PromocodeOrderManager

Attribute

  • CodeManager — manage the order's promo code.

    code: CodeManager
    

Methods

  • list — gets a list of promo codes.
  • get — gets order information.
  • create — creates an order for promo codes.
  • cancel — cancels the order for promo codes.

List

Gets a list of orders for promo codes.

async def list(
    limit: int, cursor: 
    Optional[str] = None
) -> PromocodeOrderListResponse

Parameters

  • limit — number of records to display.
  • cursor — request marker (returned in the body of response to the previous request). The parameter is not required for the first page, but is required for subsequent pages.

If the request is successful, the method returns the PromocodeOrderListResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import PromocodeManager
from yandex_b2b_go import errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    promocode_manager = PromocodeManager(client=client)
    try:
        promocodes = await promocode_manager.order.list(limit=10)
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())

Get

Gets order information.

async def get(order_id: str) -> PromocodeOrderResponse

Parameter

  • order_id — order ID.

If successful, the method returns the PromocodeOrderResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import PromocodeManager
from yandex_b2b_go import errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    promocode_manager = PromocodeManager(client=client)
    try:
        order_info = await promocode_manager.order.get(order_id='23b...89c')
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())

Create

Creates an order for promo codes.

async def create(
    promocode: Promocode, 
    idempotency_token: uuid.UUID
) -> PromocodeCreateResponse

Parameters

  • promocode — information about promo codes, class Promocode.
  • idempotency_token — idempotency token. A line in UUID format. One idempotency token corresponds to one order, so a new token must be generated for a new order.

If successful, returns the PromocodeCreateResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio
import uuid

from yandex_b2b_go import Client
from yandex_b2b_go import PromocodeManager
from yandex_b2b_go import typing, errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    promocode_manager = PromocodeManager(client=client)
    try:
        promocode = typing.Promocode(
            name='Promocode',
            value=500,
            count=20,
            active_until='2025-12-31'
        )
        token = uuid.uuid4()
        order_info = await promocode_manager.order.create(
            promocode=promocode,
            idempotency_token=token,
        )
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())

Cancel

Cancels the order for promo codes.

async def cancel(order_id: str) -> PromocodeOrderCancelResponse

Parameter

  • order_id — order ID.

If successful, the method returns the PromocodeOrderCancelResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import PromocodeManager
from yandex_b2b_go import errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    promocode_manager = PromocodeManager(client=client)
    try:
        cancel_status = await promocode_manager.order.cancel(order_id='23b...89c')
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())

CodeManager

Manage promo codes in orders.

class yandex_b2b_go.promocode.CodeManager

Method

  • list — gets information about promo codes in an order.

List

Returns information about promo codes in the order.

async def list(
    order_id: str, 
    limit: Optional[int] = None, 
    cursor: Optional[str] = None
) -> CodeListResponse

Parameters

  • order_id — order ID.
  • limit — number of records to display.
  • cursor — request marker (returned in the body of response to the previous request). The parameter is not required for the first page, but is required for subsequent pages.

If successful, the CodeListResponse class is returned.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import PromocodeManager
from yandex_b2b_go import errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    promocode_manager = PromocodeManager(client=client)
    try:
        code_info = await promocode_manager.order.code.list(order_id='23b...89c')
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())